#include <filesystem>
#include <mutex>
#include <openssl/pem.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/ssl.h>

namespace wb
{
namespace net
{
enum class ssl_file_type : int
{
    asn = SSL_FILETYPE_ASN1,
    pem = SSL_FILETYPE_PEM
};

struct ssl_context_opts
{
    std::filesystem::path certfile;
    ssl_file_type certfiletype;
    std::filesystem::path privkey;
    ssl_file_type privkeytype;
};

class ssl_context
{
  public:
    ssl_context();
    ssl_context(const ssl_context_opts& op);
    ~ssl_context();

    using handle_t = SSL_CTX*;
    handle_t native_handle()
    {
        return handle_;
    }
    const handle_t native_handle() const
    {
        return handle_;
    }

  private:
    static uint64_t ssl_context_count_;
    static std::mutex ssl_context_mtx_;
    handle_t handle_{nullptr};
};

}  // namespace net
}  // namespace wb